import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { PagesService } from '../services/pages.service';
import { NzFormatEmitEvent } from 'ng-zorro-antd';

@Injectable({
  providedIn: 'root'
})
export class RequestService {

  ownerId
  unitCode
  unitName
  isType


  constructor(public interfaceService: PagesService) { }

  /**
   * 获取未读通知数量
   */
  getUnread() {
    return new Observable<any>((observer) => {
      this.interfaceService.postPage("/erp/socket/unread", {}).subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
          if (data.code == 200) {
            observer.next(data);
          }
        }
      });
    })
  }

  getBrand() {//品牌名称
    return new Observable<any>((observer) => {	//通过引入的rxjs，传入一个异步的方法，
      this.interfaceService.getPage("/erp/product/brand/option").subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
          if (data.code == 200) {
            observer.next(data);     	//通过.next返回成功的数据
          }
        }
      });
    })
  }

  getColor() {
    return new Observable<any>((observer) => {
      this.interfaceService.postPage("/erp/product/getOption/getColor", {}).subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
          if (data.code == 200) {
            observer.next(data);
          }
        }
      });
    })
  }

  getSpec() {
    return new Observable<any>((observer) => {
      this.interfaceService.postPage("/erp/product/getOption/getSpec", {}).subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
          if (data.code == 200) {
            observer.next(data);
          }
        }
      });
    })
  }

  getProdCat1() {//商品分类
    return new Observable<any>((observer) => {
      var datas = [];
      // this.interfaceService.getPage("/product/cat/treeAll").subscribe((data: any) => {
      this.interfaceService.getPage("/erp/product/prodCat/opetion").subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
          for (var i = 0; i < data.object.list.length; i++) {
            datas.push({ title: data.object.list[i].title, key: data.object.list[i].key });
          }
          observer.next(datas);
        }
      });
    })
  }



  getPage1() {
    return new Observable<any>((observer) => {
      this.interfaceService.postPage("/erp/product/getOption/basic", {}).subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
          if (data.code == 200) {
            observer.next(data);
          }
        }
      });
    })
  }

  getPage2() {
    return new Observable<any>((observer) => {
      this.interfaceService.postPage("/erp/product/getOption/Bazaar", {}).subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
          if (data.code == 200) {
            observer.next(data);
          }
        }
      });
    })
  }

  /*getPage3(production_data){
    return new Observable<any>((observer)=>{	
      this.interfaceService.postPage("/product/getOption/production", {unitId:production_data}).subscribe((data: any) => {
        if (data.code == 200) {
          observer.next(data);  
        }
      });
    })
  }*/

  getPage3() {
    return new Observable<any>((observer) => {
      this.interfaceService.postPage("/erp/product/getOption/production", {}).subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
          if (data.code == 200) {
            observer.next(data);
          }
        }
      });
    })
  }

  getPage4() {
    return new Observable<any>((observer) => {
      this.interfaceService.postPage("/erp/product/getOption/logistics", {}).subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
          if (data.code == 200) {
            observer.next(data);
          }
        }
      });
    })
  }

  // getProdLine(unitId){//根据unitId查询存储仓库下拉
  //   return new Observable<any>((observer)=>{	
  //     this.interfaceService.postPage("/product/getOption/logistics", { unitId: unitId }).subscribe((data: any) => {
  //       if (data.code == 200) {
  //         observer.next(data);  
  //       }
  //     });
  //   })
  // }


  getProdField() {//商品自定义属性字段
    return new Observable<any>((observer) => {
      this.interfaceService.postPage("/erp/product/get/AttrAndName", {}).subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
          if (data.code == 200) {
            observer.next(data);
          }
        }
      });
    })
  }

  getProdFields(prodClsId) {//商品根据选中主表信息id查询自定义商品属性字段赋值
    return new Observable<any>((observer) => {
      this.interfaceService.postPage("/erp/product/cls/findByProdClsId", { prodClsId: prodClsId }).subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
          if (data.code == 200) {
            observer.next(data);
          }
        }
      });
    })
  }

  getProdList(prodClsId) {//商品根据选中主表信息id查询子表列表
    return new Observable<any>((observer) => {
      this.interfaceService.postPage("/erp/product/goods/ProdClsId/list", { prodClsId: prodClsId }).subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
          if (data.code == 200) {
            observer.next(data);
          }
        }
      });
    })
  }

  getProdList_gg(specGrpId) {//商品根据主表id查询明细规格下拉
    return new Observable<any>((observer) => {
      this.interfaceService.postPage("/erp/product/spec/options", { specGrpId: specGrpId }).subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
          if (data.code == 200) {
            observer.next(data);
          }
        }
      });
    })
  }

  getProd_gn(prodClsId, prodClsCode) {//商品根据主表所选商品更新功能状态
    return new Observable<any>((observer) => {
      this.interfaceService.postPage("/erp/product/cls/prodClsAuditType", { prodClsId: prodClsId, prodClsCode: prodClsCode }).subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
          if (data.code == 200) {
            observer.next(data);
          }
        }
      });
    })
  }

  get_gn(url, info_data) {//通用根据主表所选信息更新功能状态
    return new Observable<any>((observer) => {
      this.interfaceService.postPage(url, info_data).subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
          if (data.code == 200) {
            observer.next(data);
          }
        }
      });
    })
  }











}
